/*
 * Mapper.cpp
 *
 *  Created on: Jan 10, 2014
 *      Author: nick
 */

#include "Mapper.h"

//Methods
//Constructor
Mapper::Mapper() {
	type = -1;

	box.x = -1;
	box.y = -1;

	box.h = -1;
	box.w = -1;

	yVel = 0;
	xVel = 0;
}
;

Mapper::Mapper(int x, int y, int h, int w, int newType) {
	type = newType;

	box.x = x;
	box.y = y;

	box.h = h;
	box.w = w;

	xVel = 0;
	yVel = 0;
}

//Destructor
Mapper::~Mapper() {
}
;

//isWithin( SDL_Rect)
bool Mapper::isWithin(SDL_Rect * AnotherObject) {
	//The sides of the rectangles
	int leftA, leftB;
	int rightA, rightB;
	int topA, topB;
	int bottomA, bottomB;

	//Calculate the sides of rect A
	leftA = AnotherObject->x;
	rightA = AnotherObject->x + AnotherObject->w;
	topA = AnotherObject->y;
	bottomA = AnotherObject->y + AnotherObject->h;

	//Calculate the sides of rect B
	leftB = box.x;
	rightB = box.x + box.w;
	topB = box.y;
	bottomB = box.y + box.h;

	//If any of the sides from A are outside of B
	if (bottomA <= topB) {
		return false;
	}

	if (topA >= bottomB) {
		return false;
	}

	if (rightA <= leftB) {
		return false;
	}

	if (leftA >= rightB) {
		return false;
	}

	//If none of the sides from A are outside B
	return true;
	return false;
}
;

//getType
int Mapper::getType() {
	return type;
}
;

//getBox
SDL_Rect * Mapper::getBox() {
	return & box;
}
;

//getX
int Mapper::getX() {
	return box.x;
}
;

//getY
int Mapper::getY() {
	return box.y;
}
;
